package engine.newUi
{
	import engine.data.ModelLocator;
	import engine.net.event.CustomMsgEvent;
	import engine.net.messages.CustomToClientFlag;
	import engine.ui.lite.BaseUI;
	
	import flash.events.TextEvent;
	import flash.net.URLRequest;
	import flash.net.navigateToURL;
	
	import newx.com.control.window.NxWindowEvent;

	/**
	 * 公告
	 * @author wangzj
	 * 
	 */	
	public class NoticerLogic
	{
		private static var _self	:NoticerLogic; //单例
		
		private var m_Noticer:NoticerUI;
		
		public function NoticerLogic()
		{
			
		}
		
		/**
		 *  单例
		 */		
		public static function getInstance():NoticerLogic
		{
			if(_self == null)
			{
				_self = new NoticerLogic();
			}
			return _self;
		}
		/**
		 * 初始化界面
		 * 初始换所有的数据
		 */		
		public function Init():void
		{
			
			ModelLocator.getInstance().addEventListener(String(
				CustomToClientFlag.SERVER_CUSTOMMSG_GUIDE_PANEL_CONTENT),guidePanelHandler);
			
			m_Noticer = NoticerUI.getInstance();
			
		}
		
		/**
		 * 显示界面
		 * 
		 */		
		public function BeforeShow():void
		{
			addEvent();        //监听事件
			
		}
		
		/**
		 * 关闭界面
		 * 
		 */		
		public function AfterHide():void
		{
			removeEvent();
		}
		
		/**
		 * 监听事件
		 * 
		 */		
		private function addEvent():void
		{
			m_Noticer.windowBG.addEventListener(NxWindowEvent.WINDOW_CLOSE,onClickCloseHandle);
			m_Noticer.textNot.addEventListener(TextEvent.LINK , onLink);
		}
		
		/**
		 * 移除监听事件
		 * 
		 */		
		private function removeEvent():void
		{
			m_Noticer.windowBG.removeEventListener(NxWindowEvent.WINDOW_CLOSE,onClickCloseHandle);
			m_Noticer.textNot.removeEventListener(TextEvent.LINK , onLink);
		}
		
		/**
		 * 接受消息面板 
		 * @param event
		 * 
		 */		
		private function guidePanelHandler( event:CustomMsgEvent ):void
		{
			var List:Array = event.pList;
			var str:String = List[0];
			
			m_Noticer.show();
			m_Noticer.layout = BaseUI.CENTER;
			var notStr:String = "<font color='#5ee8fd'>" + str + "</font>";
			m_Noticer.textNot.htmlText = notStr;
		}
		
		private function onLink( event:TextEvent ) : void
		{
			var url:URLRequest = new URLRequest( event.text );
			navigateToURL( url );
		}
		
		private function onClickCloseHandle( event:NxWindowEvent ) : void
		{
			
			m_Noticer.showOrHide();
		
		}
		
	}
}